﻿<?php
/**
 * This is the file to define ExceptionHandler.
 * 
 * @author	Justin Yoo
 * @version	0.0.1.0001
 * @package	KYR.Core
 * 
 */

//	Checks if this file is called within the framework; otherwise terminates.
if (!defined("IS_FRAMEWORK") || !IS_FRAMEWORK)	header("Location: http://".$_SERVER["HTTP_HOST"]."/error/404");

//	Imports relevant files.
require_once CORE_PATH."KYR.Core.BaseHandler.php";
require_once HANDLER_PATH."KYR.Handlers.LogHandler.php";
require_once HANDLER_PATH."KYR.Handlers.MailHandler.php";

/**
 * This is class ExceptionHandler that processes exception.
 *
 * Processes exception.
 * 
 * @author	Justin Yoo
 * @package	KYR.Core
 * 
 */
class ExceptionHandler extends BaseHandler
{
	/**
	 * Initiates the ExceptionHandler class.
	 *
	 * @access	public
	 * @param	Request		$request		Request object that contains page request details.
	 * @param	int			$componentID	Component ID.
	 * @param	Exception	$ex				Exception.
	 *
	 */
	public function __construct($request, $componentID, $ex = null)
	{
		parent::__construct($request, $componentID);
		$this->handlerName	= __CLASS__;
		$this->error		= $ex;
		$this->log			= new LogHandler($request, $componentID, $ex);
		$this->mail			= new MailHandler($request, $componentID, $ex);
	}

	/**
	 * Processes handler.
	 *
	 * @access	public
	 * @param	array	$variables	Set of data generated by component.
	 * @exception					Throws an Exception while processing the handler.
	 *
	 */
	public function ProcessHandler(&$variables)
	{
		//	Processes the parent method.
		try { $this->ProcessHandler_($variables); } catch (Exception $ex) { throw $ex; }
		$this->log->ProcessHandler($variables);
	}
}
?>
